package com.coco.base;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.coco.service.Impl.CategoryServiceImpl;
import com.coco.service.Impl.NewsServiceImpl;
import com.coco.service.Impl.ProductServiceImpl;
import com.coco.service.Impl.UserServiceImpl;

/**
 * Servlet implementation class BaseServlet
 */
public class BaseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    protected UserServiceImpl userServiceImpl = new UserServiceImpl();
    protected CategoryServiceImpl categoryServiceImpl = new CategoryServiceImpl();
    protected NewsServiceImpl newsServiceImpl = new NewsServiceImpl();
    protected ProductServiceImpl productServiceImpl=new ProductServiceImpl();
    
    public BaseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String method = request.getParameter("action");
		Class<? extends BaseServlet> clz = this.getClass();
		try {
			Method m = clz.getDeclaredMethod(method, HttpServletRequest.class,HttpServletResponse.class );
			m.setAccessible(true);
			m.invoke(this, request,response);
		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
				
		}
	}

	 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
